<?php

/*
 * employe/select-formation.phtml
 */
?>
<?php
$formations	 = $this->formations;
$count		 = $this->count;
$matricule	 = $this->matricule;
?>

<div class="empl-border">
    <?php if ($count > 0): ?>
	<?php foreach ($formations as $d): ?>
	    <div class="empl-full vert-olive">
		<a href="#" class="select-formation" data-formation="<?php echo $d->id; ?>" data-matricule="<?php echo $matricule; ?>"><?php echo $d->libelle; ?></a>
	    </div>
	<?php endforeach; ?>
    <?php else: ?>
        <div class="empl-full bleu">Aucun Diplôme dans la base de données</div>
    <?php endif; ?>
    <div class="empl-full">
	&nbsp;<a href="<?php echo $this->url('RHX/default', array('controller'	 => 'formation', 'action'	 => 'index')) ?>" class="btn btn-info close-after"  target="_blank" style="float:right;">Aller à la gestion des formations &nbsp;&nbsp;<i class='icon-white icon-home'></i></a>
    </div>
</div>

<script type="text/javascript">
    // Démarrage
    $(function(){
	// Selection de formation
	$('.select-formation').click(function(e){
	    e.preventDefault();
	    formation = $(this).attr('data-formation');
	    matricule = $(this).attr('data-matricule');
	    ajax = $.ajax({
		dataType: 'json',
		type: 'post',
		url : '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'addformation')) ?>',
		data: '&formation=' + formation + '&matricule=' + matricule
	    });
	    ajax.done(function(result){
		if(result.etat){
		    // Enregistrement réussie
		    f = result.formation;
		    ef = result.employeFormation;
		    formations = '<div  style="position: relative"><div class="empl-full vert-olive" id="f' + ef.id + '">' + f.libelle + '</div><div class="cancel-icon"><a href="#" onclick="return deleteSomething(\'<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'deleteFormation')) ?>\', \'' + ef.id + '\', \'Voulez-vous effacer la Formation ?\', \'f\');" title="Effacer la Formation"><img src="<?php echo $this->basePath() . '/img/rhx/close-12x12.png' ?>" title="Effacer la Formation"></a></div></div>';
		    $('#formations-list').hide().append(formations).fadeIn('normal');
		    //window.location.reload();
		    $('#formation-none').hide('fast');
		    $('#dialog1').dialog('close');
    <?php if ((int) $matricule == 0): ?>
                                                	    $('#newEmploye').append("<input type='hidden' id='form-f" + ef.id + "' name='formations[]' value='" + result.formation.id + "'>");
    <?php endif; ?>
		}
	    });
	    ajax.fail(function(){});
	});
	$('.close-after').click(function(){
				$('#dialog1').dialog('close');
			    });
    });
</script>